package com.passer.web.travel.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.passer.common.annotation.Log;
import com.passer.common.enums.BusinessType;
import com.passer.web.travel.domain.TMap;
import com.passer.web.travel.service.ITMapService;
import com.passer.common.core.controller.BaseController;
import com.passer.common.core.domain.AjaxResult;
import com.passer.common.utils.poi.ExcelUtil;
import com.passer.common.core.page.TableDataInfo;

/**
 * 地图信息Controller
 *
 * @author passer
 * @date 2021-11-23
 */
@Controller
@RequestMapping("/travel/map")
public class TMapController extends BaseController
{
    private String prefix = "travel/map";

    @Autowired
    private ITMapService tMapService;

    @RequiresPermissions("travel:map:view")
    @GetMapping()
    public String map()
    {
        return prefix + "/map";
    }

    /**
     * 查询地图信息列表
     */
    @RequiresPermissions("travel:map:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TMap tMap)
    {
        startPage();
        List<TMap> list = tMapService.selectTMapList(tMap);
        return getDataTable(list);
    }

    /**
     * 导出地图信息列表
     */
    @RequiresPermissions("travel:map:export")
    @Log(title = "地图信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TMap tMap)
    {
        List<TMap> list = tMapService.selectTMapList(tMap);
        ExcelUtil<TMap> util = new ExcelUtil<TMap>(TMap.class);
        return util.exportExcel(list, "地图信息数据");
    }

    /**
     * 新增地图信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存地图信息
     */
    @RequiresPermissions("travel:map:add")
    @Log(title = "地图信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TMap tMap)
    {
        return toAjax(tMapService.insertTMap(tMap));
    }

    /**
     * 修改地图信息
     */
    @GetMapping("/edit/{pid}")
    public String edit(@PathVariable("pid") Long pid, ModelMap mmap)
    {
        TMap tMap = tMapService.selectTMapById(pid);
        mmap.put("tMap", tMap);
        return prefix + "/edit";
    }

    /**
     * 修改保存地图信息
     */
    @RequiresPermissions("travel:map:edit")
    @Log(title = "地图信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TMap tMap)
    {
        return toAjax(tMapService.updateTMap(tMap));
    }

    /**
     * 删除地图信息
     */
    @RequiresPermissions("travel:map:remove")
    @Log(title = "地图信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tMapService.deleteTMapByIds(ids));
    }
}
